
/*********************************
*通用javascript库
*
*author: zhang jianyi 2005 11-1 整理
*
*******************************/

/****
*获取应用程序根路径

*载asp.net的无cookie session 方式下，提取sessionIDs 
*
***********/
function Application_GetRoot(){
		
		var pathArr =  window.location.pathname.split("/") ;
		
		if( pathArr.length == 1 ){
			return "/";
		}else if( pathArr.length == 2 ){
			return pathArr[0];
		}else{
			
			if( pathArr[0] == "" ){  //模式对话框

			 
				if( pathArr[2].indexOf("(") > -1 &&  pathArr[2].indexOf(")") > -1 )
					return "/" + pathArr[1] + "/" + pathArr[2] ;
				else
					return "/" + pathArr[1];
					
			}else{
			
				if( pathArr[2].indexOf("(") > -1 &&  pathArr[2].indexOf(")") > -1 )
					return "/" + pathArr[0] + "/" + pathArr[1] ;
				else
					return "/" + pathArr[0];
			
			}
			 
		}
			
}

			function showCal(obj)
{

			if (!obj) var obj = event.srcElement;
			var obDate;
			
			if ( obj.value == "" ) {
				obDate = new Date();
			} else {
			
				var v = obj.value;
				var arr = v.split( " " );
				if( arr.length > 1 ) v = arr[0];
				
				var obList = v.split( "-" );
				if(obList.length !=3) 
				{obDate = new Date();}
				else
				{obDate = new Date( obList[0], obList[1]-1, obList[2] );}
			}
			
			//url = "../Common/calendar/calendarFrame.aspx?date=" + obj.value ;
			url = "../Common/Calendar/dlgCal.htm";
			
			//alert( event.srcElement.offsetTop );
			
			x = event.x + window.screenLeft ;//+ document.body.scrollLeft + document.body.scrollTop
			y = event.y + window.screenTop;
		
			
			var retVal = showModalDialog( url  , obDate , 
				"dialogWidth=206px; dialogHeight=206px; help=no; scroll=no; status=no;dialogLeft=" + x + ";dialogTop=" + y );
				
			if ( retVal != null && typeof(retVal) != "undefined" ) {
				var year = retVal.getFullYear();
				var month = retVal.getMonth()+1;
				var day = retVal.getDate();
				obj.value =year + "-" + month + "-" + day;
				//obj.value = retVal ;
				//Form1.submit();
			}
}		

 

//********************
/**
*页面选择基函数

*@param string IDElement  name属性s
*@param string NameElement /newCommon/choose/中的页面名

*@param string page 
*/
function baseChoose( IDElement, NameElement, page , param ){
	if( typeof( param ) == "undefined" )
		param = "dialogWidth=300px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
		
	var idObj = document.Form1.item( IDElement );
	var nameObj = document.Form1.item( NameElement );
	
 
	
	if( idObj == null ){
		alert( "IDElement参数错误！（找不到指定元素 IDElement:" + IDElement + "）" );
		return;
	}
	
	if( nameObj == null ){
		alert( "NameElement参数错误！（找不到指定元素 NameElement:" + NameElement  + "）" );
		return;
	}
	
	var o = new Object();
	
	o.SelectedUserNames = nameObj.value;
	o.SelectedUserIDs =  idObj.value;
	
	//window.open( Application_GetRoot() + "/" + page );

	var r = window.showModalDialog( "../" + page, o , param );
	
	if( r==null ) return;
	nameObj.value = r.SelectedUserNames;
	idObj.value = r.SelectedUserIDs;
	

}
/*********
*选择页面必须返回 o.List 
*@param eList 要设置的隐藏域列表 name1,name2,name3
*
*
***********/
function baseChoose2( eList , page , param ){
	if( typeof( param ) == "undefined" )
		param = "dialogWidth=300px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	
	arr = eList.split( "," );
	var valueArr = new Array();
	var obj ; 
	for( i = 0 ; i < arr.length ; i ++ ){
		if( arr[i] == "" ){
			valueArr[i] = "" ;
			continue ;
		}
		obj = document.Form1.item( arr[i] );
		if( obj == null ){
			alert( "eList参数错误！（找不到指定元素 :" + arr[i] + "）" );
			return ;
		}
		valueArr[i] = obj.value ;
	}
	
	var o = new Object();
	o.List =  valueArr;
	
	//window.open( Application_GetRoot() + "/" + page );

	var r = window.showModalDialog( "../" + page, o , param );
	
	if( r==null ) return;
	
//	alert(  (r.List.length) == null  );

	for( i = 0 ; i < arr.length ; i ++ ){
		if( arr[i] == "" ) continue ;
		obj = document.Form1.item( arr[i] );
		obj.value = r.List[i]; 
		//alert( obj.value );
	}

}

//---------------------------------------------------------------------------
// Created by 王少明 :请选择下拉列表基类
//---------------------------------------------------------------------------
function baseChoose3( obj, page , param ){
	if( typeof( param ) == "undefined" )
		param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
		
	var thisObj = document.Form1.item( obj );
	
	if( thisObj == null ){
		//alert( "NameElement参数错误！（找不到指定元素 NameElement:" + NameElement  + "）" );
		return;
	}
	
	var o = new Object();
	
	//o.SelectedUserNames = thisObj.text;
	o.SelectedUserIDs =  thisObj.value;	
	//window.open( Application_GetRoot() + "/" + page );

	var r = window.showModalDialog( "../" + page, o , param );
	
	if( r==null ) return;
	try{thisObj.value = r.SelectedUserIDs}catch(e){alert("列表中没有该值");};
	

}
//张建义 2005 11 18 
//选择某一部门下合同

function CompanyContractSelect( eList ){
	var url = "Common/Dialog/CompanyContractSelect_Frame.aspx?enableMultiSelect=false" ;
	param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose2( eList , url , param ) ;
}

function CompanyContractSelect2( eList ,mode ){
	var url = "Common/Dialog/CompanyContractSelect_Frame.aspx?Mode="+mode+"&enableMultiSelect=false" ;
	param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose2( eList , url , param ) ;
}

//张建义 2005 11 19
//选择数据字典
function DictionarySelect( NameElement, IDElement , dicName ){
 
	var url = "Common/Dialog/DictionaryDialog.aspx?DicCode=" + escape( dicName ) ;
	//PopUpWindow(url);
	//return ;
	param = "dialogWidth=300px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose( IDElement , NameElement , url , param ) ;
}

//张建义 2005 11 18 
//选择某一部门下用户

function ChooseDeptUser( NameElement, IDElement , enableMultiSelect ,ChooseDepart){
	var url = "Common/UserDialog/DeptUserSelect.aspx?enableMultiSelect=" + enableMultiSelect+"&ChooseDepart="+ChooseDepart ;
	//param = "dialogWidth=300px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose(IDElement, NameElement , url  ) ;
}

//made by 王少明 2005.12.12
//单位选择
function OpenCompany ( NameElement ,IDElement , param,IsMy)
{
	if(  IsMy != null )
	var url = "Common/Dialog/CompanySelect_Frame.aspx?IsMy="+IsMy;
	else
	var url = "Common/Dialog/CompanySelect_Frame.aspx";

	var param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose ( IDElement,NameElement,url , param );
}

//made by 王少明 2005.12.12过滤合同类型
//单位选择
function OpenCompany2 ( NameElement ,IDElement ,param, Mode,IsMy)
{
	//alert(IsMy != null);
	if(  IsMy != null )
		var url = "Common/Dialog/CompanySelect_Frame.aspx?Mode="+Mode+"&IsMy="+IsMy;
	else
		var url = "Common/Dialog/CompanySelect_Frame.aspx?Mode="+Mode ;
	
	//alert(url);
	if(param =="")
	{param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"}
	baseChoose ( IDElement,NameElement,url , param );
}

//made by 王少明 2005.12.12
//单位选择
function SelectCompany (obj , param,IsMy)
{
	if(  IsMy != null )
	var url = "Common/Dialog/CompanySelect_Frame.aspx?IsMy="+IsMy;
	else
	var url = "Common/Dialog/CompanySelect_Frame.aspx";

	var param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose3 ( obj,url , param );
}

//made by 王少明 2005.12.12过滤合同类型
//单位选择
function SelectCompany2 ( obj ,param, Mode,IsMy)
{
	//alert(IsMy != null);
	if(  IsMy != null )
		var url = "Common/Dialog/CompanySelect_Frame.aspx?Mode="+Mode+"&IsMy="+IsMy;
	else
		var url = "Common/Dialog/CompanySelect_Frame.aspx?Mode="+Mode ;
					
	//alert(url);
	if(param =="")
	{param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"}
	baseChoose3 ( obj,url , param );
}


//made by 蒋晓明 2005.11.4
//人员选择
function OpenPerson( NameElement , IDElement )
{
	var url = "Common/Dialog/PersonSelect_Frame.aspx";
	baseChoose ( IDElement,NameElement,url );
}
//选择本部门下用户
function chooseSelfDetpUser1( eList ){
	var url = "common/dialog/chooseSelfDeptUser.aspx?enableMultiSelect=true";
	baseChoose2( eList , url ) ;
}

function chooseSelfDetpUser( IDElement, NameElement){
	var url = "common/dialog/chooseSelfDeptUser.aspx?enableMultiSelect=false";
	baseChoose(IDElement, NameElement , url ) ;
}
function chooseSelfDetpUsers( IDElement, NameElement){
	var url = "common/dialog/chooseSelfDeptUser.aspx?enableMultiSelect=true";
	baseChoose(IDElement, NameElement , url ) ;
}
 
 

function chooseDept( IDElement, NameElement){
	var url = "common/dialog/chooseOrg.aspx?enableMultiSelect=false";
	baseChoose(IDElement, NameElement , url ) ;
}
function chooseDepts( IDElement, NameElement){
	var url = "common/dialog/chooseOrg.aspx?enableMultiSelect=true";
	baseChoose(IDElement, NameElement , url ) ;
}

 

function chooseUsers( eList ){
	var url = "common/dialog/choose/main.aspx?enableMultiSelect=true";
	var param = "dialogWidth=600px; dialogHeight=400px; help=no;status=no; scroll=no; resizable=yes;";
	baseChoose2( eList , url , param ) ;
}


  


var popUpWin=0;
function PopUpWindow(URLStr, left, top, width, height , newWin )
{
	if( typeof( newWin ) == "undefined"  )
		newWin = false ;
		
	if( typeof( left ) == "undefined"  )
		left = 100 ;
	if( typeof( top ) == "undefined"  )
		top = 20 ;
		
	if( typeof( width ) == "undefined"  )
		width = 800 ;
		
	if( typeof( height ) == "undefined"  )
		height = 600 ;

		
	if( newWin ){
		open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		return ;
	}	
	
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus() ;	
}

function PopUpPrint(URLStr,left, top, width, height)
{	
	
	if( typeof( left ) == "undefined"  )
		left = 0 ;
	if( typeof( top ) == "undefined"  )
		top = 0 ;
		
	if( typeof( width ) == "undefined"  )
		width = screen.availWidth*0.99 ;
		
	if( typeof( height ) == "undefined"  )
		height = screen.availHeight*0.89  ;

	open(URLStr, "", "toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width="+width+",height="+height+",left="+left+",top="+top+"");
}
//刷新父窗口

function ReflashParentWindow()
{
	window.opener.location.href=window.opener.location.href;
	window.location.reload;
}

//使页面所有元素处于disable状态

function DisableAllElement(){
		for( i = 0; i < document.Form1.elements.length; i++ ){
			curObj = document.Form1.elements(i);
			//if( ( curObj.type=="button" D)  ) continue;//&& ( curObj.name="back" || curObj.name="close" )
			curObj.disabled = true;	
		}
}

//使页面所有输入元素处于readonly状态，所有选择元素处于disable状态

function DisableAllInputElement(){
 
		for( i = 0; i < document.Form1.elements.length; i++ ){
			curObj = document.Form1.elements(i);
			if( curObj.type=="text" || curObj.type == "textarea" ){
				curObj.readOnly = true;	
			}
			else if( curObj.type == "radio" || curObj.type == "checkbox" )
				curObj.disabled = true;	
		}
}

//启用页面所有元素

function EnableAllElement(){
		for( i = 0; i < document.Form1.elements.length; i++ ){
			curObj = document.Form1.elements(i);
			//if( ( curObj.type=="button" )  ) continue;//&& ( curObj.name="back" || curObj.name="close" )
			curObj.disabled = false;	
		}
}

//通过name属下隐藏元素
function HiddenByName( name ){
		try{
			var obj = document.all( name );
			if( obj == null )return;
			obj.style.display = "none";
		}catch(e){}
}
		

//察看附件
function ViewFile(id){
	var url = Application_GetRoot() + "/common/dialog/showFile.aspx?fileID=" + id;
	 
	_left = 0;
	_top = 0;
	_width = screen.Width;
	_height = screen.Height; 
	
	//var win = open( url, 'win', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+_width+',height='+_height+',left='+_left+', top='+_top+',screenX='+_left+',screenY='+_top+'');
	//win.focus() ;	 

}
//下载附件
function DownloadFile(id){
	var url = Application_GetRoot() + "/common/dialog/showFile.aspx?isDownload=1&fileID=" + id;
	PopUpWindow( url, 0, 0, screen.Width, screen.Height ) ; 
}
 
/****************************附件 END ***************/
 
 //获取选择列表
 //@name string 复选框的name
 function GetCheckedList(name){
	var list = "";
	for( i = 0; i < document.Form1.elements.length; i++ ){
		curObj = document.Form1.elements(i);
		if( curObj.type == "checkbox" && curObj.name == name && curObj.checked ){
				if( list != "" ) list += ",";
				list += curObj.value;
		}				  
	}
	return list;
 }
 
 //选中页面所有复选框
 //@name string 复选框的name
 function SelectAllCheckbox(){
	for( i = 0; i < document.Form1.elements.length; i++ ){
		curObj = document.Form1.elements(i);
		if( curObj.type == "checkbox"   )
 			  curObj.checked = true;
	}
 }
  //取消选中页面所有复选框
 function UnSelectAllCheckbox(){
	for( i = 0; i < document.Form1.elements.length; i++ ){
		curObj = document.Form1.elements(i);
		if( curObj.type == "checkbox"   )
 			  curObj.checked = false ;
	}
 }
 
  //设置页面所有复选框选中状态

  //@b bool 是否选中
  function SetAllCheckboxStatus( b ){
	for( i = 0; i < document.Form1.elements.length; i++ ){
		curObj = document.Form1.elements(i);
		if( curObj.type == "checkbox"   ){
		        if(curObj.name!="IsBJ")
 			  curObj.checked = b ;
 			  }
	}
 }
 
 //设置页面指定名的复选框选中状态

 //@name string 复选框的name
 //@b bool 是否选中
  function SetCheckboxStatus( name , b){
	for( i = 0; i < document.Form1.elements.length; i++ ){
		curObj = document.Form1.elements(i);
		if( curObj.name != name ) continue ;
		if( curObj.type == "checkbox"   )
 			  curObj.checked = b ;
	}
 }
 

 
 function GetQueryString(){
	var arr = window.location.href.split("?");
	if( arr.length == 1 ) return "";
	else return arr[1];
 }
 
 /***********
 *下拉列表操作
 *
 *
 *****************/
 
function CreateOption(text,value){
			var oOption = document.createElement("OPTION");
			oOption.text=text;
			oOption.value=value;
			return oOption;
}
		
/********
*移动下拉列表中所有项
*@fromObj 要移动的列表对象
*&toObj 移动到的列表对象
*************/
function MoveAllOption( fromObj , toObj ){
			var toOp ;
			var fromOp
			var i = 0 ;
			for( i = 0 ; i < fromObj.options.length ; i ++ ){
				fromOp = fromObj.options( i );
				toOp = createOption( fromOp.text , fromOp.value  ) 
				toObj.add( toOp ) ;
			}
 
			for( i =  fromObj.options.length - 1 ; i >= 0 ; i -- ){
				fromObj.remove(i);
			} 
}
/********
*移动下拉列表中所有选中项

*@fromObj 要移动的列表对象
*&toObj 移动到的列表对象
*************/
function MoveSelectedOption( fromObj , toObj ){
		
			///alert( fromObj.selectedIndex )   ;
			
			var toOp ;
			var fromOp
			var i = 0 ;
			for( i = 0 ; i < fromObj.options.length ; i ++ ){
				
				fromOp = fromObj.options( i );
				if( !fromOp.selected  ) continue ;
				toOp = createOption( fromOp.text , fromOp.value  ) 
				toObj.add( toOp ) ;
			}
 
			for( i =  fromObj.options.length - 1 ; i >= 0 ; i -- ){
				fromOp = fromObj.options( i );
				if( fromOp.selected  ) fromObj.remove(i);
			} 
}
		
//返回(若为弹出窗口则关闭	
function CloseBack( url ){

		if( typeof(url) != "undefined" && url != "" ){
			self.location = url ;
			return ;
		}
		//alert(self.location);
		if( top.location != self.location ){
			history.back();
		}
		else{
			window.close();
		}
}	
	
 
//将内存中的信息粘贴到剪切板

	//作者：王小平   修改时间：2002.6.7
function Paste2Word()
{
	   try{
			var wApp = new ActiveXObject("Word.Application");
			wApp.visible = true ;
			wApp.Documents.add();
			wApp.Selection.PasteSpecial();
	    }
	   catch(e)
	   {
		alert ("请正确安装Word或设置IE的安全选项！");
		return false;
	   }
}

//将指定的html代码转到word里面显示
//作者：王小平   修改时间：2002.6.7
function Str2Word(str)
{
		var printWindow=window.open("","PrintWindow","width=10,height=10,left=10000,top=10000");
		printWindow.document.write ( "<link rel='stylesheet' href='/evaluate/style/main.css'/>" );
		printWindow.document.write (str);
		printWindow.document.execCommand ("selectall");
		printWindow.document.execCommand ("copy");	
		printWindow.close();
		paste2Word();
}
	
/*
*打印字符串

*@author zhangjianyi
*@param string str 要打印的字符串，一般用div 的 innerHTML 取得
*/
function PrintString( str ){
		var printWindow=window.open("","PrintWindow","width=10,height=10,left=10000,top=10000");
		//		var printWindow=window.open("","PrintWindow","width=10,height=10,left=10,top=10");
		printWindow.document.write ( "<link rel='stylesheet' href='/evaluate/style/main.css'/><br>" );
		printWindow.document.write (str);
		printWindow.document.execCommand ("print");
		
		//printWindow.document.execCommand ("copy");	
		
		printWindow.close();
	
}
	
	//
function PrintPage(){
		document.execCommand ("print");
		document.execCommand ("close");
}
	
	/*打印御览
	*@str 要御览的Html字符串

	*
	*/
function PrintViewStr( str ){
		//	var printWindow=window.open("","PrintWindow","width=10,height=10,left=10000,top=10000");
		var printWindow=window.open("","PrintWindow","toolbar=no, menubar=yes, scrollbars=yes,resizable=yes,location=no, status=no");

		printWindow.document.write ( "<link rel='stylesheet' href='/Pdhr/skin/main.css'/><br>" );

		printWindow.document.write (str);
		printWindow.focus();
	
}
	
	/* 改变对象显示（显示或隐藏）

	*
	*@obj 要改变显示的对象
	*/
function ChangeDisplay( obj  , display ){
	
	
	
	if( typeof( display ) == "undefined" ) {
	
		if( obj.style.display == "" )
			obj.style.display = "none" ;
		else
			obj.style.display = "" ;	
			
	}else{
	
		if( display )
			obj.style.display = "" ;
		else
			obj.style.display = "none" ;	
		
	}
	
}


function OpenReckoning (NameElement,IDElement,param)
{
	var url = "Common/Dialog/ReckoningSelect_Frame.aspx";

	var param = "dialogWidth=650px; dialogHeight=550px; help=no;status=no; scroll=no; resizable=yes;"
	baseChoose ( IDElement,NameElement,url , param );
}

//用于表格行变色

var rowNo = 0;
var row_marked = Array();
var row_over_color;
var row_marked_color;

function onRowOver(row, rowNo)
{
  if(row_marked[rowNo]==null||!row_marked[rowNo]){
    // use row.bgColor save ori color since it has no effect if has style backgroundColor
    row.bgColor=row.style.backgroundColor;
    row.style.backgroundColor=row_over_color!=null?row_over_color:'#DDE8ED';
  }
}
function onRowOut(row, rowNo)
{
  if(row_marked[rowNo]==null||!row_marked[rowNo]){
    row.style.backgroundColor=row.bgColor;
    row.bgColor='';
  }
}
function onRowClicked(row, rowNo)
{
  // FIXME: following several lines only works on IE
  whichIt = event.srcElement;
	while (whichIt.tagName != "A") {
		whichIt = whichIt.parentElement;
		if (whichIt == null){
			// no link clicked, passed
			break;
		}
	}
	if (whichIt != null){
	  return;
	}
	if(row_marked[rowNo]==null||!row_marked[rowNo]){
	  row_marked[rowNo]=true;
	  row.style.backgroundColor = row_marked_color!=null?row_marked_color:'#FFCC99';
	}
	else{
	  row_marked[rowNo]=false;
	  row.style.backgroundColor = row_over_color!=null?row_over_color:'#DDE8ED';
	}
}
